<template>
  <!--诉讼管理-->
  <section class="page system-parameter-manage">
    <data-form :model="queryModel" @onSearch="refreshData" autoSearch @handleResetForm="follFeedback">
      <!--输入区域-->
      <template slot="inputs">
        <el-form-item label="借据号" prop="caseNumber">
          <el-input v-model="queryModel.caseNumber"></el-input>
        </el-form-item>
        <el-form-item label="客户姓名" prop="personalName">
          <el-input v-model="queryModel.personalName"></el-input>
        </el-form-item>
        <el-form-item label="手机号" prop="mobileNo">
          <el-input v-model="queryModel.mobileNo"></el-input>
        </el-form-item>
        <el-form-item label="身份证号" prop="idCard">
          <el-input v-model="queryModel.idCard"></el-input>
        </el-form-item>
        <el-form-item label="机构" prop="departmentType">
          <el-select v-model="queryModel.departmentType" placeholder="所有" clearable>
            <el-option v-for="{index,name,code} in $dict.getDictData('DepartmentType')" :key="index" :label="name" :value="code"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="案件金额">
          <number-range v-model="queryModel.outAmount"></number-range>
        </el-form-item>
        <el-form-item label="逾期阶段" prop="overduePeriod">
          <el-select v-model="queryModel.overduePeriod" placeholder="请选择" clearable>
            <el-option v-for="{index,name,code} in $dict.getDictData('OverduePeriodStatus')" :key="index" :label="name" :value="code.replace(/M|\+/, '')"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="逾期天数">
          <number-range v-model="queryModel.overdueDays"></number-range>
        </el-form-item>
        <el-form-item label="系统来源" prop="sysCode">
          <el-select v-model="queryModel.sysCode" placeholder="请选择" clearable>
            <el-option v-for="{index,name,code} in $dict.getDictData('SysCode')" :key="index" :label="name" :value="code.replace(/M|\+/, '')"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="产品名称" prop="productName">
          <el-input v-model="queryModel.productName"></el-input>
        </el-form-item>
        <el-form-item label="诉讼编号" prop="lawNumber">
          <el-input v-model="queryModel.lawNumber"></el-input>
        </el-form-item>
        <el-form-item label="案件创建时间" prop="creatTime">
          <el-date-picker type="daterange" :editable="false" v-model="queryModel.creatTime" placeholder="选择日期时间" clearable>
          </el-date-picker>
        </el-form-item>
      </template>
    </data-form>
    <data-box @onPageChange="refreshData" :data="stayDataList" :selectionList.sync="selectionList" :page="pageService">
      <template slot="buttons">
        <el-button @click="selectCase" v-auth = "1025">分案</el-button>
      </template>
      <template slot="columns">
        <!--数据列区域-->
        <el-table-column label="借据号" :min-width="$helper.getColumnWidth(8)">
          <template slot-scope="scope">
            <a  @click="openExecutionPage(scope.row)">{{scope.row.caseNumber}}</a>
          </template>
        </el-table-column>
        <el-table-column prop="lawNumber" label="诉讼编号" :min-width="$helper.getColumnWidth(3)" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="personalName" label="客户姓名" :min-width="$helper.getColumnWidth(4)">
        </el-table-column>
        <el-table-column prop="mobileNo" label="手机号" :formatter="(row)=>$filter.encryptPhone(row.mobileNo)" :min-width="$helper.getColumnWidth(5)">
        </el-table-column>
        <el-table-column prop="idCard" label="身份证号" :formatter="(row)=>$filter.encryptIDCardFour(row.idCard)" :min-width="$helper.getColumnWidth(8)">
        </el-table-column>
        <el-table-column prop="area" label="地区" :min-width="$helper.getColumnWidth(3)">
        </el-table-column>
        <el-table-column prop="overdueAmount" label="案件金额" :min-width="$helper.getColumnWidth(3)">
        </el-table-column>
        <el-table-column prop="overduePeriod" label="逾期阶段" :min-width="$helper.getColumnWidth(3)">
        </el-table-column>
        <el-table-column prop="overdueDays" label="逾期天数" :min-width="$helper.getColumnWidth(3)">
        </el-table-column>
        <el-table-column prop="sysCode" label="系统来源" :formatter="(row) => $filter.encryptSysCode(row.sysCode)" :min-width="$helper.getColumnWidth(3)" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="productName" label="产品名称" :min-width="$helper.getColumnWidth(3)">
        </el-table-column>
        <!-- <el-table-column prop="customerCategory" label="顾客类型" :min-width="$helper.getColumnWidth(5)" :formatter="(row) => $filter.dictConvert(row.customerCategory, 'CustomerCategory')">
        </el-table-column> -->
        <el-table-column prop="currentCollectorName" label="电催催收员" :min-width="$helper.getColumnWidth(4)">
        </el-table-column>
        <el-table-column prop="createTime" label="案件创建时间" :formatter="(row) => $filter.dateTimeFormat(row.createTime)" :min-width="$helper.getColumnWidth(5)">
        </el-table-column>
      </template>
    </data-box>

    <!--弹框-分案-->
    <el-dialog title="选择受托方" @close="dialog.selectEntrusted = false" :visible.sync="dialog.selectEntrusted" :close-on-click-modal="false" :show-close="false">
      <select-entrusted :isLawsuit="true" :selectedCaseIds="selectedCaseIds" @close="dialog.selectEntrusted=false;refreshData()" @success="refreshData"></select-entrusted>
    </el-dialog>

  </section>
</template>

<script lang="ts">
import Vue from "vue";
import Component from "vue-class-component";
import { Auth, Layout, Dependencies } from "~/core/decorator";
import DataForm from "~/components/common/data-form.vue";
import DataBox from "~/components/common/data-box.vue";
import NumberRange from "~/components/common/number-range.vue";
import SelectEntrusted from "~/components/outsource-manage/case-allot/select-entrusted.vue";
import { namespace } from 'vuex-class';
import { PageService } from "~/utils/page.service";
import { SortService } from '~/utils/sort.service';

import { OutsourceLawsuitStayService } from "~/services/domain-service/outsource-lawsuit-manage.service";
import { OpenExecutionData } from "~/config/types";
import { ApplyType, CASE_CHANNEL, CASE_HALT_CATEGORY, } from '~/config/enum.config';
const CollectionExecutionModule = namespace('collection-execution');
import { FilterService } from '~/utils/filter.service';

// @Auth(1010)
@Layout("workspace")
@Component({
  components: {
    DataForm,
    DataBox,
    NumberRange,
    SelectEntrusted
  }
})
export default class LawsuitManageIndex extends Vue {
  @Dependencies(OutsourceLawsuitStayService) private outsourceLawsuitStayService: OutsourceLawsuitStayService;
  @Dependencies(PageService) private pageService: PageService;
  @Dependencies(SortService) private sortService: SortService;
  @CollectionExecutionModule.Action private openCollectionExecution;

  private dialog: any = {
    selectEntrusted: false
  };

  private queryModel: any = {
    caseNumber: '',
    personalName: '',
    mobileNo: '',
    idCard: '',
    departmentType: '',
    outAmount: {
      max: '',
      min: '',
    },
    overduePeriod: '',
    overdueDays: {
      max: '',
      min: '',
    },
    turnSource: '',
    sysCode: '',
    creatTime: [],
    lawNumber: ''
  }
  private stayDataList: any[] = [];//数据列表
  private selectionList: any[] = [];//选中数据
  private temp: any = {};//选中数据
  private tempData: any = []

  private mounted() {
    this.refreshData();
  }

  private selectCase() {
    if (this.selectionList.length === 0) {
      this.$message.info('请选择需要分案的案件');
      return;
    }
    this.dialog.selectEntrusted = true;
  }

  private refreshData() {
    this.selectionList = []
    //默认加载列表
    this.outsourceLawsuitStayService.searchPendingList(this.queryModel, this.pageService).subscribe(
      data => {
        this.stayDataList = data;
        if(this.stayDataList){
          this.stayDataList.forEach(x=>{
            x.overduePeriod>12?x.overduePeriod = 'M12+':x.overduePeriod = 'M'+x.overduePeriod
          })
        }
      }
    );
  }
  /**
   * 进入查看执行页
   */
  private openExecutionPage(row) {
    this.openCollectionExecution(new OpenExecutionData(row.caseId, row.caseNumber, CASE_CHANNEL.OUTER, true,true))
  }

  // 重置numberRange
  private follFeedback() {
    this.queryModel.outAmount = { min: '', max: '' };
    this.queryModel.overdueDays = { min: '', max: '' };

  }

  private get selectedCaseIds() {
    return this.selectionList.map(v => v.id)
  }
}
</script>

<style lang="less" >
</style>
